package com.example.demo.controller;

import com.example.demo.pojo.PublicFields;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.InboundDTO;
import com.example.demo.pojo.dto.OutboundDTO;
import com.example.demo.pojo.query.InboundQuery;
import com.example.demo.pojo.query.OutboundQuery;
import com.example.demo.pojo.vo.InboundVO;
import com.example.demo.pojo.vo.OutboundVO;
import com.example.demo.pojo.vo.PageVO;
import com.example.demo.service.IOutboundService;
import com.example.demo.service.imply.IInboundServiceImply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "出库相关接口")
@RequestMapping("/outbound")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080"}, allowCredentials = "true")
public class OutboundController {
    private final IOutboundService outboundService;
    @ApiOperation("出库物资")
    @PostMapping("/add")
    public Result addComponent(@RequestBody OutboundDTO outboundDTO) {

        int result=outboundService.addOutbound(outboundDTO, PublicFields.newInstance());
        if(result==-1){
            return Result.error("库存不足");
        }
        return Result.success("出库成功");
    }
    @ApiOperation("批量清除出库表数据")
    @PostMapping("/delete")
    public Result deleteOutbound(@RequestBody List<Long> ids){

        outboundService.deleteOutbound(ids);

        return Result.success("删除成功");
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<PageVO<OutboundVO>> page(OutboundQuery outboundQuery){

        return Result.success(outboundService.queryOutboundPage(outboundQuery));
    }
}
